package it.test.dao;

import javax.resource.ResourceException;
import javax.resource.cci.ConnectionFactory;
import javax.resource.cci.Interaction;
import javax.resource.cci.Record;

import org.springframework.jca.cci.core.InteractionCallback;
import org.springframework.jca.cci.core.support.CciDaoSupport;
import org.springframework.jca.cci.core.support.CommAreaRecord;

import com.ibm.connector2.cics.ECIInteractionSpec;





public class DAOHost extends CciDaoSupport{

	public String getData(final String inputString) throws ResourceException{
		final ECIInteractionSpec interactionSpec = new ECIInteractionSpec();
		interactionSpec.setFunctionName("TEST");
		interactionSpec.setInteractionVerb(ECIInteractionSpec.SYNC_SEND_RECEIVE);
		
		@SuppressWarnings({ "unchecked", "rawtypes" })
		String output = (String) getCciTemplate().execute(
				new InteractionCallback(){
					public Object doInInteraction(Interaction interaction, ConnectionFactory factory)
								throws ResourceException {
					Record input = new CommAreaRecord(inputString.getBytes());
					Record output = new CommAreaRecord();
					interaction.execute(interactionSpec, input, output);
					return new String(output.toString());
					}
				});
		return output;
		
	}
	
}
